package cn.broadsense.common.utils;

import cn.broadsense.common.exception.UtilException;

import java.util.Random;

/**
 * @author huangjinshi
 * @description
 * @createDate 2023-09-13 15:04:40
 */
public class SmsUtils {

    public static String generateCaptcha(int n) {
        if (n <= 0) {
            throw new UtilException("长度不能小于0");
        }
        String str = "123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int number = random.nextInt(9);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
